home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 2635 < prev    next >
Encoding:
Text File  |  1996-08-05  |  1.7 KB  |  49 lines

  1. Newsgroups: comp.lang.c
  2. Path: Utrecht.NL.net!news
  3. From: E.H.Terwiel@inter.NL.net (E.H. Terwiel (Erik))
  4. Subject: Re: ? pointer to array of pointers
  5. X-Nntp-Posting-Host: utr99-167.utrecht.nl.net
  6. Message-ID: <DLLMKD.GEy@inter.NL.net>
  7. Sender: news@inter.NL.net (News at newsutr)
  8. Organization: NLnet
  9. X-Newsreader: Forte Free Agent 1.0.82
  10. References: <4e0ckd$ht1@badger.wmin.ac.uk>
  11. Date: Mon, 22 Jan 1996 20:04:17 GMT
  12.  
  13. kruppd@westminster.ac.uk (Declan Kruppa) wrote:
  14.  
  15. >I am trying to use some routines in "Numerical Recipies in C"
  16. >The book gives code for a function char **matrix which allocates
  17. >memory for a
  18. >a pointer to an array of ponters. If I call this function with
  19. >a=matrix(1,10,1,10) it seems to work ok and I can access the elements of 
  20. >the array using a[i][j]   . 
  21. >However I would like to be able to step through the array using pointer
  22. >notation such as *p++ or **p++ . What would be the notation to step through the 10000 elements sequentily using pointer notation. 
  23.  
  24. >Also I would like to write the pointer to a file stream like:
  25. >File *fp
  26. >fp=fopen("FILE","wb");
  27. >fwrite(a,1,10000,fp);
  28.  
  29. >but when I read back the file it is not at all what I expect. 
  30. >I think that *p is a ponter to the rows in the matrix so I would expect it to 
  31. >step through every 10th element in the array. I don't know how to access
  32. >sequential elements a[1][1], a[1][2] etc using pointer arithmetic or how to 
  33. >write it to a file.
  34. >Any help appreciated. 
  35.  
  36. >Declan Kruppa
  37. >University of Westminster
  38.  
  39. Watch out for Num recip.
  40.  
  41. The code is not very good, obvious translation from FORTRAN.
  42. Also it is said that the authors are not very knowledgeable on the
  43. various subjects.
  44.  
  45. Also: arrays start at index 1 instead of 0 !!!!!
  46.  
  47. Erik
  48.  
  49.